<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>首页</title>

<!-- 引入基础的Ext的JS和CSS文件-->
<%@ include file="/common/meta_ext.jsp"%>

<!-- 引入所需的扩展组件 -->
<script src="${ctx}/common/system/public/js/IconMultiSelect.js" type="text/javascript"></script>
<script src="${ctx}/common/system/org/js/ac-user-shortcut/SelectMenuTree.js" type="text/javascript"></script>
<script src="${ctx}/common/system/org/js/ac-user-shortcut/ShortcutListPanel.js" type="text/javascript"></script>
<script src="${ctx}/common/system/org/js/ac-user-shortcut/ShortcutSettingPanel.js" type="text/javascript"></script>

<script type="text/javascript">
Ext.onReady(function(){
	
	Ext.QuickTips.init();

    var settingPanel = new Ext.ux.org.acusershortcut.ShortcutSettingPanel({
    	imagePath: '${ctx}/resources/images/icons/48_48/',
    	margins: '1 1 1 1'
    });
    
    var btnPanel = new Ext.Panel({
    	region: 'south',
    	frame: true,
    	margins: '0 1 1 1',
    	height: 60,
    		layout: 'hbox',
    		layoutConfig: {
                  pack: 'end',
                  align: 'middle'
            },
            defaults:{margins:'0 10 0 0'},
			items:[{
				xtype: 'button',
				text: '保存',
				width: 80,
				iconCls: 'icon-middle-save',
				scale: 'large',
				handler: function(button, e){
					updateShortCuts();
				}
			},{
				xtype: 'button',
				text: '重置',
				width: 80,
				iconCls: 'icon-middle-reset',
				scale: 'large',
				handler: function(button, e){
					settingPanel.listFormPanel.list.store.reload();
				}
			}]
		});
    
	var viewport = new Ext.Viewport({
		layout: 'border',
		items: [settingPanel, btnPanel]
	});
	
	//处理将树节点移动到列表框中
	var dropTarget = new Ext.dd.DropTarget(settingPanel.list.el, {   
		ddGroup: settingPanel.ddGroup,   
		notifyDrop: function(dd, e, data){   
			settingPanel.addMenuToList(dd.dragData.node, settingPanel);
			return true;
		}
	});
	
	//更新用户的快捷菜单设置
	var updateShortCuts = function(){
		var newShortcutIdStr = settingPanel.listFormPanel.list.getValues('value');
		var newShortcutIds = 0;
		if(newShortcutIdStr != ""){
			newShortcutIds = newShortcutIdStr.split(',');
		}
		
		Ext.Ajax.request({
			url: 'ac-user-shortcut!updateAllForCurUser.action',
			success: function(response){
				Ext.Msg.alert('系统提示', '更新快捷菜单成功!');
			},
			failure: function(){
				Ext.Msg.alert('系统提示', '更新快捷菜单失败!');
			},
			method: 'POST',
			params: {
				newShortcutIds: newShortcutIds
			}
		});
		
	}
});
</script>
</head>
<body>
</body>
</html>